package com.colorful.insuranceproject.utils;

import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import com.colorful.insuranceproject.R;
import com.jungly.gridpasswordview.GridPasswordView;

/**
 * 支付密码输入包装器
 * Created by lovely3x on 16/7/30.
 */
public class PaymentPasswordInputMethodWrapper extends FrameLayout implements View.OnKeyListener {

    private GridPasswordView mPasswordInput;

    private NumericPasswordInputMethod inputMethod;
    private View mBackgroundView;

    public PaymentPasswordInputMethodWrapper(Context context) {
        this(context, null);
    }

    public PaymentPasswordInputMethodWrapper(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public PaymentPasswordInputMethodWrapper(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        LayoutInflater.from(getContext()).inflate(R.layout.view_payment_password_input_method_wrapper, this, true);
        mPasswordInput = (GridPasswordView) findViewById(R.id.gpv_view_payment_password_input_method_wrapper_input);
        inputMethod = (NumericPasswordInputMethod) findViewById(R.id.npim_view_payment_password_input_method_wrapper_input_method);
        this.mBackgroundView = findViewById(R.id.v_view_payment_password_input_method_wrapper_background);
        inputMethod.setOnKeyListener(this);
    }

    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        if (mPasswordInput != null) {
            mPasswordInput.performKeyEvent(event);
        }
        return false;
    }

    public GridPasswordView getGridPasswordView() {
        return mPasswordInput;
    }

    public View getBackgroundView() {
        return mBackgroundView;
    }
}
